import { Router } from 'express'
import { analyzeEmotion } from '../services/emotionAnalysis.js'

export const emotionRouter = Router()

// POST /api/emotion/analyze - Analyze emotion from text
emotionRouter.post('/analyze', async (req, res, next) => {
  try {
    const { text } = req.body as { text?: string }
    
    if (!text || typeof text !== 'string') {
      res.status(400).json({
        success: false,
        error: 'Text is required',
      })
      return
    }
    
    const result = await analyzeEmotion(text)
    res.json(result)
  } catch (error) {
    next(error)
  }
})
